<template>
	<view class="page-appoint">
		<view class="atv">
			<view class="atvsv">
				<view  :class="{atc:currentTab==1}" @click="currentTabs(1)">正在授权</view>
			</view>
			
			<view class="atvsv">
				<view :class="{atc:currentTab==2}" @click="currentTabs(2)">完成授权</view>
			</view>
		</view>
		
		<view @click="qx" v-if="currentTab==1" class="qxsq">取消授权</view>
		<view class="navs">
			<view class="appoint-item" :class="{itv:cur==item.id}"  @click="xz(item)" v-for="item in list" :key="item.id">
					<view>授权序号：{{item.id}}</view>
					<view>委托时间：{{item.create_time}}</view>
					<view>货&#12288;&#12288;名：{{item.hname}}</view>
					<view>船&#12288;&#12288;名：{{item.shipnam}}</view>
					<view>航&#12288;&#12288;次：{{item.hc}}</view>
					<view>委托单号：{{item.orderons}}</view>
					<view>授权车队：{{item.cdname}}</view>
					<view>保税授权：{{item.swg==1?'授权':'未授权'}}</view>
					<view v-if="item.dnum!=null && item.dnum!='' && item.dnum!='0' && item.dnum!=0">授权吨数：{{item.dnum}}吨</view>
					<view>货&#12288;&#12288;主：{{item.hzdwid}}</view>
					<view>授权时间：{{item.sqstartime}}-{{item.sqendtime}}</view>
			</view>
		</view>
		<view class="appoint-item"  v-if="list.length==0">
				<view >暂无预约数据</view>
		</view>
		<tabBar :pagePath="'/pages/lshz/lshzyuy'"></tabBar>
	</view>

</template>

<script>
	import {
	  request
	} from '@/util/request.js'
	export default {
		data() {
			return {
				udata:'',
				list:[],
				currentTab:1,
				cur:'',
				cdid:'',
				xzinfo:'',
			}
		},
		created() {
			this.getuserinfo()
		},
		onShow() {
			this.getuserinfo()
			
		},
		methods: {
			sectionChange(index) {
				this.current = index;
			},
			xz(e){
				this.cur =e.id
				this.xzinfo = e
			},
			currentTabs(e){
				this.currentTab = e
				this.init()
			},
			
			async bangd(e){
					uni.navigateTo({
						url:'/pages/adduser/adduser?yid='+e.id+'&cdid='+e.cdid
					})
			},
			async erweima(e){
					uni.navigateTo({
						url:'/pages/erweima/erweima?yid='+e.id+'&cdid='+e.cdid
					})
			},
			async detailyuy(e){
					uni.navigateTo({
						url:'/pages/detailyuy/detailyuy?id='+e.id
					})
			},
			async getuserinfo(){
				let data = {
					id:uni.getStorageSync('uid')
				}
				let res =  await this.$api.getuserinfo(data)
				console.log(res.data.code)
				if(res.data.code==0){
					uni.setStorageSync('uid', res.data.data.id);
					uni.setStorageSync('cdtype', res.data.data.cdtype);
					this.udata = res.data.data
					this.cdid = res.data.data.cdid
					this.init()
				}
			},
			async init() {
				let data = {
					uid:uni.getStorageSync('uid'),
					hzdwid:this.udata.hzdwid,
					currentTab:this.currentTab,
					cdid:this.cdid
				}
				// let res = await this.$api.gethzorderonsalllist(data)
				let res = await request('/api/Lshz/gethzsqlist/', 'post',data)
				console.log(res.data.data)
				this.list = res.data.data
			},
			
			qx(e){
				let that = this
				uni.showModal({
					title: '是否取消当前授权',
					content: '取消授权',
					success: function (res) {
						if (res.confirm) {
							that.delcdorderons(e)
							console.log('用户点击确定');
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});	
			},
			
			
			async delcdorderons(e){
				if(this.cur==''){
					uni.showToast({
					  title: '没有选择数据',	
					  icon:'none',
					  duration: 2000
					});
					return false;
				}
				if(e.ygbstatus==2 && this.currentTab==1){
					uni.showToast({
					  title: '当委托不能取消',	
					  icon:'none',
					  duration: 2000
					});
					return false;
				}
				let data = {
					id:this.cur
				}
				console.log(data)
				let res = await this.$api.qxorderoncddel(data)
				console.log(res.data.data)
				if(res.data.code==0){
					let data1 = {
						uid:uni.getStorageSync('uid'),
						msg:'车队'+this.xzinfo.cdname+'被取消授权',
						lv:1,
						type:5,
						cz:JSON.stringify(this.xzinfo)
					}	
					await this.$api.addlogs(data1)
					uni.showToast({
					  title:  res.data.msg,	
					  icon:'none',
					  duration: 2000
					});
					this.init()
				}else{
					uni.showToast({
					  title: res.data.msg,	
					  icon:'none',
					  duration: 2000
					});
				}
			},
		
		}
	}
</script>

<style lang="scss" scoped>
	.page-appoint{
			font-size: 14px;
			box-sizing: border-box;
			background-color: #e6e6e6;
			min-height: 800px;
			margin-bottom: 100px;
			padding-bottom:100px;
		}
		.fv{
			float: left;
			border: 3upx solid #3c77b7;
			padding: 10upx;
			margin-left: 30upx;
		}
		.atvsv{
			width: 50%;
			float: left;
			// height: 100upx;
			color: #6d6d6d;
			font-size: 18px;
			background-color: #FFFFFF;
		}
		.atc{
			color: #FFFFFF;
			font-size: 15px;
			background-color: #3c77b7;
			height: 100upx;
		}
		.atv{
			width: 100%;
			height: 100upx;
			overflow: hidden;
		}
	
		.atvsv view{
			display: block;
			line-height: 80upx;
			text-align: center;
			height: 80upx;
			width: 100%;
		}
	.navs{
		
	}	
	.appoint-item {
		display: block;
		width: 96%;
		background-color: #ffffff;
		margin: 0 auto;
		font-size: 18px;
		padding: 20upx;
		border-radius: 5px;
		padding: 40upx;
		position: relative;
		margin-bottom: 20upx;
		>view {
			font-size: 18px;
			margin-bottom: 20upx;
		}
	}
	.itv{
		background-color: #3c77b7;
		color: #ffffff;
	}
	.qxsq{
		width: 98%;
		background-color: #c80806;
		height: 50px;
		line-height: 50px;
		text-align: center;
		font-size: 20px;
		color: #FFFFFF;
		border-radius: 10px;
		margin: 5px auto;
	}
	
	
</style>
